#include "action.h"

/**
 * The -print action.
 */
int print_action(const char *dir, struct dirent *entry)
{
    printf("%s/%s\n", dir, entry->d_name);
    return 1;
}

/**
 * The -print0 action.
 */
int print0_action(const char *dir, struct dirent *entry)
{
    printf("%s/%s", dir, entry->d_name);
    putchar('\0');
    return 1;
}

/**
 * Interface to check if given string is an action.
 */
int is_action(const char *str)
{
    return (NULL != str) && (
            (0 == strcmp("-print", str)) || 
            (0 == strcmp("-print0", str)));
}

/**
 * Interface to get action.
 */
action get_action(const char *action_name, char *args[])
{
    if(0 == strcmp("-print", action_name)) {
        return print_action;
    } else if (0 == strcmp("-print0", action_name)) {
        return print0_action;
    } 

    return NULL;
}

